<?php
namespace App\Services;
use Illuminate\Support\Facades\Cache;

class CodeService{
    //此方法只用于注册和重置密码使用
    public function send($phone,$templateCode){
        $code = $this->code($phone);
        if(app()->environment('local')) return $code;
        app(AliYunService::class)->sms($phone,$templateCode,['code'=>$code]);
        return $code;
    }


    protected function code($phone){
        //缓存是否存在 key
        if(Cache::get($phone)) abort(403,'请稍后再试');
        //Cache::put($phone,$code = mt_rand(100000,999999),config('my.code.out_time',180));
        Cache::put($phone,$code = 952700,config('my.code.out_time',180));
        return $code;
    }

}
